package com.sky.mapper;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    List<Dish> selectAllDish(DishPageQueryDTO dishPageQueryDTO);


    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish (name,category_id,price,image,description,status,create_time,update_time,create_user,update_user)" +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insertDish(Dish dish);

    @Select("select * from dish where id=#{id}")
    Dish selectById(Integer id);

    void deleteById(List<Integer> ids);

    @Select("select * from dish where id =#{id}")
    DishVO getById(Long id);

    void updateById(DishVO dishVO);

    @Update("update dish set status=#{status} where id = #{id}")
    void updateStatusById(Integer status, Long id);

    @Select("select * from dish where category_id=#{categoryId}")
    List<DishVO> selectDishByCategoryId(Long categoryId);

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> selectBySetmealId(Long id);

    @Select("select setmeal_id from setmeal_dish where dish_id = #{id}")
    List<Long> selectDishBySetmealId(Long id);

    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> selectDishById(Long categoryId);
}